package edu.jmu.aspectj.xml;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 切面类
 * 
 *
 */
public class MyAspect {
	//前置通知
	public void myBefore(JoinPoint joinPoint){
		System.out.println("前置通知，目标");
		System.out.print(joinPoint.getTarget()+",方法名称：");
		System.out.println(joinPoint.getSignature().getName());
	}
	//后置通知
	public void myAfterReturning(JoinPoint joinPoint){
		System.out.print("后置通知，方法名称:"+joinPoint.getSignature().getName());
	}
	
	//环绕通知
	/**
	 * ProceedingJoinPoint是JoinPoint的子接口，表示可以执行目标方法
	 * @param proceedingJoinPoint 必须接收一个参数，类型为ProceedingJoinPoint
	 * @return 必须返回Object类型值
	 * @throws Throwable 必须throws Throwable
	 */
	public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
		System.out.println("环绕开始");
		Object object = proceedingJoinPoint.proceed();
		System.out.println("环绕结束");
		return object;
	}
	
	public void myAfterThrowing(JoinPoint joinPoint,Throwable e){
		System.out.println("异常通知:出错了!"+e.getMessage());
	}
	
	//最终通知
	public void myAfter(){
		System.out.println("最终通知!");
	}
}
